package com.xea.action;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.fileupload.util.Streams;

import com.xea.model.Channel;
import com.xea.model.Product;
import com.xea.model.ProductPath;
import com.xea.service.ChannelService;
import com.xea.service.ProductPathService;
import com.xea.service.ProductService;
import com.xea.service.ServiceFactory;
import com.xea.util.FileUtil;
import com.xea.util.ImageUtil;
import com.xea.util.StringUtil;

public class ProductAction extends DispatcherServlet{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1932405126946046616L;
	
	/**
	 * 查询所有类别
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	public void searchchannel(HttpServletRequest request,HttpServletResponse response) throws Exception{
		ChannelService channelDao = ServiceFactory.getChannelService();
		request.setAttribute("datas", channelDao.search());
		response.setCharacterEncoding("utf-8");
		RequestDispatcher dispatcher=request.getRequestDispatcher("inner/admin/product/left.jsp");
		dispatcher.forward(request, response);	
	}
	
	/**
	 * 查询所有类别
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	public void searchoutchannel(HttpServletRequest request,HttpServletResponse response) throws Exception{
		ChannelService channelDao = ServiceFactory.getChannelService();
//		List<Channel> list=channelDao.search(0);
//		String st="";
//		if(list.size()!=0){
//			for (Channel channel : list) {
//				st+="<tr>";
//				st+="<td height='26' align='center'>&nbsp;</td>";
//				List<Channel> list1=channelDao.search(channel.getId());
//				if(list1.size()==0)
//					st+="<td height='26' align='left'><strong><a name='menu' id='"+channel.getId()+"' href="+"javascript:menuClick('"+request.getContextPath()+"/product?m=searchout&channelId="+channel.getId()+"',"+channel.getId()+")><strong>"+channel.getName()+"</strong></a></strong></td>";
//				else
//					st+="<td height='26' align='left'><strong>"+channel.getName()+"</strong></td>";
//				st+="</tr>";
//				for (Channel channel2 : list1) {
//					st+="<tr>";
//					st+="<td height='26' align='center'>&nbsp;</td>";
//					List<Channel> list2=channelDao.search(channel2.getId());
//					if(list2.size()==0)
//						st+="<td height='26' align='left'><a name='menu' id='"+channel2.getId()+"' href="+"javascript:menuClick('"+request.getContextPath()+"/product?m=searchout&channelId="+channel2.getId()+"',"+channel2.getId()+")>&nbsp;├ "+channel2.getName()+"</strong></a></td>";
//					else
//						st+="<td height='26' align='left'>&nbsp;├ "+channel2.getName()+"</td>";
//					st+="</tr>";
//					for (Channel channel3 : list2) {
//						st+="<tr>";
//						st+="<td height='26' align='center'>&nbsp;</td>";
//						st+="<td height='26' align='left'><a name='menu' id='"+channel3.getId()+"' href="+"javascript:menuClick('"+request.getContextPath()+"/product?m=searchout&channelId="+channel3.getId()+"',"+channel3.getId()+")>&nbsp;&nbsp;&nbsp;&nbsp;┗"+channel3.getName()+"</strong></a></strong></td>";
//						st+="</tr>";
//					}
//				}
//			}
//		}
//		request.setAttribute("str", st);
		List<Channel> list=channelDao.search();
		request.setAttribute("list", list);
		response.setCharacterEncoding("utf-8");
		RequestDispatcher dispatcher=request.getRequestDispatcher("outer/product/left.jsp");
		dispatcher.forward(request, response);	
	}
	
	/**
	 * 查询所属类别产品
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	public void search(HttpServletRequest request,HttpServletResponse response) throws Exception{
		ProductService productDao = ServiceFactory.getProductService();
		String name=request.getParameter("proname");
		String channelId=request.getParameter("channelId");
		if(StringUtil.isNullOrEmpty(name))
			name="";
		String pageNo=request.getParameter("pageNo");
		if(StringUtil.isNullOrEmpty(pageNo))
			pageNo="";
		request.setAttribute("pagedata", productDao.search(name,Integer.valueOf(channelId), pageNo));
		response.setCharacterEncoding("utf-8");
		RequestDispatcher dispatcher=request.getRequestDispatcher("inner/admin/product/list.jsp");
		dispatcher.forward(request, response);	
	}
	
	/**
	 * 查询所属类别产品
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	public void searchout(HttpServletRequest request,HttpServletResponse response) throws Exception{
		ProductService productDao = ServiceFactory.getProductService();
		String name=request.getParameter("proname");
		String channelId=request.getParameter("channelId");
		if(StringUtil.isNullOrEmpty(name))
			name="";
		String pageNo=request.getParameter("pageNo");
		if(StringUtil.isNullOrEmpty(pageNo))
			pageNo="";
		if(StringUtil.isNullOrEmpty(channelId))
			request.setAttribute("pagedata", productDao.searchout(name, pageNo));
		if(!StringUtil.isNullOrEmpty(channelId))
			request.setAttribute("pagedata", productDao.searchout(name,Integer.valueOf(channelId), pageNo));
		response.setCharacterEncoding("utf-8");
		RequestDispatcher dispatcher=request.getRequestDispatcher("outer/product/list.jsp");
		dispatcher.forward(request, response);	
	}
	
	/**
	 * 新增产品
	 * @param request
	 * @param response
	 * @throws IOException 
	 * @throws ServletException 
	 */
	public void add(HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException{
		ProductService productDao = ServiceFactory.getProductService();
		response.setCharacterEncoding("GBK"); 
        // 获得容器中上传文件夹所在的物理路径   
        String channelId="";
        try {   
        	DiskFileItemFactory fac = new DiskFileItemFactory();   
            ServletFileUpload upload = new ServletFileUpload(fac);   
            upload.setHeaderEncoding("UTF-8");   
            // 获取多个上传文件   
            List fileList = upload.parseRequest(request);   
            // 遍历上传文件写入磁盘   
            Iterator it = fileList.iterator();  
            String pno="";
            String name="";
            String material="";
            String volume="";
            String describes=""; 
            String pub="";
            String sortNo="";
            int num=0;
            while (it.hasNext()) {   
                FileItem item = (FileItem) it.next();   
                if(item.isFormField()){
                	if ("pno".equals(item.getFieldName())) {
                		pno=new String(item.getString("UTF-8"));
                	}
                	else if ("channelId".equals(item.getFieldName())) {
                		channelId=new String(item.getString("UTF-8"));
                	}
                	else if ("name".equals(item.getFieldName())) {
                		name=new String(item.getString("UTF-8"));
                	}
                	else if ("material".equals(item.getFieldName())) {
                		material=new String(item.getString("UTF-8"));
                	}
                	else if ("volume".equals(item.getFieldName())) {
                		volume=new String(item.getString("UTF-8"));
                	}
                	else if ("describes".equals(item.getFieldName())) {
                		describes=new String(item.getString("UTF-8"));
                	}
                	else if ("pub".equals(item.getFieldName())) {
                		pub=new String(item.getString("UTF-8"));
                	}
                	else if ("sortNo".equals(item.getFieldName())) {
                		sortNo=new String(item.getString("UTF-8"));
                	}
                }    
            }   
//          if(productDao.find(name, Integer.valueOf(channelId))!=null){
//    			PrintWriter out = response.getWriter();
//    	        out.print("<script>window.parent.Finish('所属类别产品名称已存在,请重新输入');</script>");  
//    			return;
//    		}
            if(productDao.findByPno(pno)!=null){
    			PrintWriter out = response.getWriter();
    	        out.print("<script>window.parent.Finish('产品编号已存在,请重新输入');</script>");  
    			return;
    		}
            if(productDao.isSortNo(sortNo)==true){
    			PrintWriter out = response.getWriter();
    	        out.print("<script>window.parent.Finish('产品排序序号已存在,请重新输入');</script>");  
    			return;
    		}
    		productDao.add(new Product(pno,Integer.valueOf(channelId), name, material, volume, describes, new Date(), Integer.valueOf(pub), 0,null, Integer.valueOf(sortNo)));
    		Product product=productDao.findByPno(pno); 
            it = fileList.iterator(); 
            while (it.hasNext()) {   
                FileItem item = (FileItem) it.next();   
                // 如果item是文件上传表单域      
                // 获得文件名及路径     
                
                if (item.getName()!= null && item.getName()!="") {
                	System.out.println("getTomcatPicTempUploadPath=:"+FileUtil.getTomcatPicTempUploadPath());
                	System.out.println("getTomcatPicUploadPath=:"+FileUtil.getTomcatPicUploadPath());
                	File tomcatPathFile = new File(FileUtil.getTomcatPicTempUploadPath());
            		if (!tomcatPathFile.isDirectory())
            			tomcatPathFile.mkdirs();
            		File file = new File(FileUtil.getTomcatPicUploadPath());
                    if (!file.isDirectory()) {   
                        file.mkdirs();   
                    } 
                    String fileName = item.getName().substring(item.getName().lastIndexOf("\\")+1);
                	String fname = FileUtil.removeSuffix(item.getName().substring(item.getName().lastIndexOf("\\")+1));
                	String ext = FileUtil.getSuffix(item.getName());
             		String path = FileUtil.getPicUploadPath();
             		String tomcatPath = FileUtil.getTomcatPath();
             		String randomName = FileUtil.getPicRandomName();
            		String middlePath = path+FileUtil.getMiddlePicName(randomName, ext);
            		String smallPath = path+FileUtil.getSmallPicName(randomName, ext);
            		File tFile = new File(FileUtil.getTomcatPicTempUploadPath()+fileName);
            		File middlePic = null;
            		File smallPic = null;
            		try {
            			BufferedInputStream in = new BufferedInputStream(item.getInputStream());// 获得文件输入流   
                		BufferedOutputStream outStream = new BufferedOutputStream(new FileOutputStream(tFile));// 获得文件输出流   
                		Streams.copy(in, outStream, true);// 开始把文件写到你指定的上传文件夹 
            		} catch (Exception e) {     			
            			e.printStackTrace();
            		}
            		try {
            			smallPic = ImageUtil.getFixedBoundFile(tFile, Integer.parseInt("150"), Integer.parseInt("196"));
            			smallPic.renameTo(new File(tomcatPath+smallPath));
            		} catch (Exception e) {
            			e.printStackTrace();
            		}
            		try {
            			middlePic = tFile;
            			middlePic.renameTo(new File(tomcatPath+middlePath));
            			ImageUtil.markImage(tomcatPath+middlePath);
            		} catch (Exception e) {
            			e.printStackTrace();
            		}
                     //保存到数据库     
                    ProductPath productpath=new ProductPath(product.getId(), "", middlePath, smallPath, fname, 1);
                    ProductPathService productpathDao = ServiceFactory.getProductPathService();
                    product.setCoverPath(smallPath);
                    productDao.updatePath(product);
                    productpathDao.add(productpath);
                    FileUtil.deleteFile(tFile);
                    num++;
                }
            }
            if(num>0){
            	productDao.updatenum(num,product.getId());
            }
            
        } catch (FileUploadException ex) {   
            ex.printStackTrace();      
            return;   
        } 
        PrintWriter out = response.getWriter();
        out.print("<script>window.parent.jSuccess('添加成功',null,function(r){window.parent.productform.reset();window.parent.location.href='"+request.getContextPath()+"/product?m=search&channelId="+channelId+"';});</script>");  
	}
	
	/**
	 * 查看产品详情
	 * @param request
	 * @param response
	 * @throws IOException
	 * @throws ServletException 
	 */
	public void findById(HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException{
		ProductService productDao = ServiceFactory.getProductService();
		ProductPathService productpathDao = ServiceFactory.getProductPathService();
		String id=request.getParameter("id");
		request.setAttribute("product", productDao.findById(Integer.valueOf(id)));
		request.setAttribute("productpath", productpathDao.search(id));
		response.setCharacterEncoding("utf-8");
		RequestDispatcher dispatcher=request.getRequestDispatcher(request.getParameter("_url"));
		dispatcher.forward(request, response);
	}
	
	/**
	 * 查看产品详情
	 * @param request
	 * @param response
	 * @throws IOException
	 * @throws ServletException 
	 */
	public void findByIdout(HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException{
		ProductService productDao = ServiceFactory.getProductService();
		ProductPathService productpathDao = ServiceFactory.getProductPathService();
		String id=request.getParameter("id");
		request.setAttribute("product", productDao.findById(Integer.valueOf(id)));
		request.setAttribute("productpath", productpathDao.searchout(id));
		response.setCharacterEncoding("utf-8");
		RequestDispatcher dispatcher=request.getRequestDispatcher(request.getParameter("_url"));
		dispatcher.forward(request, response);
	}
	
	/**
	 * 查看产品详情
	 * @param request
	 * @param response
	 * @throws IOException
	 * @throws ServletException 
	 */
	public void detail(HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException{
		ProductService productDao = ServiceFactory.getProductService();
		ProductPathService productpathDao = ServiceFactory.getProductPathService();
		String id=request.getParameter("id");
		request.setAttribute("product", productDao.findById(Integer.valueOf(id)));
		request.setAttribute("productpath", productpathDao.search(id));
		response.setCharacterEncoding("utf-8");
		RequestDispatcher dispatcher=request.getRequestDispatcher("inner/admin/product/detail.jsp");
		dispatcher.forward(request, response);
	}
	
	/**
	 * 删除产品跟产品路径
	 * @param request
	 * @param response
	 * @throws IOException 
	 */
	public void del(HttpServletRequest request,HttpServletResponse response) throws IOException{
		ProductService productDao = ServiceFactory.getProductService();
		ProductPathService productpathDao = ServiceFactory.getProductPathService();
		String id=request.getParameter("id");
		productDao.del(id);
		List<ProductPath> list=productpathDao.search(id);
		if(list.size()!=0){
			for (ProductPath productPath : list) {
				FileUtil.deleteFile(new File(FileUtil.getTomcatPath()+productPath.getSmallPath()));
				FileUtil.deleteFile(new File(FileUtil.getTomcatPath()+productPath.getMiddlePath()));
				System.out.println("del smallpath path:"+FileUtil.getTomcatPath()+productPath.getSmallPath());
			}
		}
		productpathDao.delpro(id);
		
	}
	
	/**
	 * 修改产品
	 * @param request
	 * @param response
	 * @throws IOException 
	 */
	public void update(HttpServletRequest request,HttpServletResponse response) throws IOException{
		ProductService productDao = ServiceFactory.getProductService();
		String id=request.getParameter("id");
		String pno=request.getParameter("pno");
        String name=request.getParameter("name");
        String material=request.getParameter("material");
        String volume=request.getParameter("volume");
        String describes=request.getParameter("describes");
        String pub=request.getParameter("pub");
        String sortNo=request.getParameter("sortNo"); 
//      String channelId=request.getParameter("channelId");
        System.out.println("sortNo：=========="+sortNo);
		response.setCharacterEncoding("utf-8");
		JSONObject json=new JSONObject();
		System.out.println("进来==========");
//		Product product=productDao.find(name,Integer.valueOf(channelId), Integer.valueOf(id));
//		if(product!=null){
//			PrintWriter out = response.getWriter();
//			json.put("msg", "所属类别产品名称已存在,请重新输入!");
//			out.print(json.toString());
//			out.close();
//			return;
//		}
        if(productDao.findByPno(pno,Integer.valueOf(id))!=null){
			PrintWriter out = response.getWriter();
			json.put("msg", "产品编号已存在,请重新输入!");
			out.print(json.toString());
			out.close();
			return;
		}
        if(productDao.isSortNo(sortNo,Integer.valueOf(id))==true){
			PrintWriter out = response.getWriter();
			json.put("msg", "产品排序序号已存在,请重新输入!");
			out.print(json.toString());
			out.close();
			return;
		}
        Product produ=productDao.findById(Integer.valueOf(id));
        produ.setName(name);
        produ.setDescribes(describes);
        produ.setMaterial(material);
        produ.setPno(pno);
        produ.setPub(Integer.valueOf(pub));
        produ.setVolume(volume);
        produ.setSortNo(Integer.valueOf(sortNo));
        productDao.update(produ);
	}
	/**
	 * 查看产品图片
	 * @param request
	 * @param response
	 * @throws IOException
	 * @throws ServletException 
	 */
	public void searchPic(HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException{
		ProductPathService productpathDao = ServiceFactory.getProductPathService();
		String id=request.getParameter("id");
		String name=request.getParameter("picName");
		if(StringUtil.isNullOrEmpty(name))
			name="";
		request.setAttribute("productpath", productpathDao.search(Integer.valueOf(id),name));
		response.setCharacterEncoding("utf-8");
		RequestDispatcher dispatcher=request.getRequestDispatcher(request.getParameter("_url"));
		dispatcher.forward(request, response);
	}
	
	/**
	 * 删除图片跟修改图片数量
	 * @param request
	 * @param response
	 * @throws Exception 
	 * @throws NumberFormatException 
	 */
	public void delPic(HttpServletRequest request,HttpServletResponse response) throws NumberFormatException, Exception{
		ProductService productDao = ServiceFactory.getProductService();
		ProductPathService productpathDao = ServiceFactory.getProductPathService();
		String id=request.getParameter("id");
		String proid=request.getParameter("proid");
		if(id.indexOf(",")==-1){
			ProductPath pro=productpathDao.findById(Integer.valueOf(id));
			FileUtil.deleteFile(new File(FileUtil.getTomcatPath()+pro.getSmallPath()));
			FileUtil.deleteFile(new File(FileUtil.getTomcatPath()+pro.getMiddlePath()));
			productDao.modifyPicNum(Integer.valueOf(proid), -1);
		}
		else
		{
			String[] str=id.split(",");
			for (int i = 0; i < str.length; i++) {
				ProductPath pro=productpathDao.findById(Integer.valueOf(str[i]));
				FileUtil.deleteFile(new File(FileUtil.getTomcatPath()+pro.getSmallPath()));
				FileUtil.deleteFile(new File(FileUtil.getTomcatPath()+pro.getMiddlePath()));
				
			}
			productDao.modifyPicNum(Integer.valueOf(proid), str.length*-1);
		}
		productpathDao.del(id);
	}
	
	/**
	 * 公开产品
	 * @param request
	 * @param response
	 * @throws IOException 
	 */
	public void pub(HttpServletRequest request,HttpServletResponse response) throws IOException{
		ProductService productDao = ServiceFactory.getProductService();
		String id=request.getParameter("id");
		String pub=request.getParameter("pub");
		productDao.pub(id,Integer.valueOf(pub));
	}
	
	/**
	 * 设置首页产品展示
	 * @param request
	 * @param response
	 * @throws IOException 
	 */
	public void setcover(HttpServletRequest request,HttpServletResponse response) throws IOException{
		ProductService productDao = ServiceFactory.getProductService();
		ProductPathService productpathDao = ServiceFactory.getProductPathService();
		Product product= productDao.findById(Integer.valueOf(request.getParameter("proid")));
		ProductPath productpath= productpathDao.findById(Integer.valueOf(request.getParameter("id")));
		product.setCoverPath(productpath.getSmallPath());
		productDao.updatePath(product);
	}
	
	/**
	 * 新增图片
	 * @param request
	 * @param response
	 * @throws Exception 
	 * @throws NumberFormatException 
	 */
	public void addPic(HttpServletRequest request,HttpServletResponse response) throws NumberFormatException, Exception{
		ProductService productDao = ServiceFactory.getProductService();
		response.setCharacterEncoding("GBK"); 
		String id="";
        // 获得容器中上传文件夹所在的物理路径   
        try {   
        	DiskFileItemFactory fac = new DiskFileItemFactory();   
            ServletFileUpload upload = new ServletFileUpload(fac);   
            upload.setHeaderEncoding("UTF-8");   
            // 获取多个上传文件   
            List fileList = upload.parseRequest(request);   
            // 遍历上传文件写入磁盘   
            Iterator it = fileList.iterator();  
            int num=0;
            while (it.hasNext()) {   
                FileItem item = (FileItem) it.next();   
                if(item.isFormField()){
                	if ("id".equals(item.getFieldName())) {
                		id=new String(item.getString("UTF-8"));
                	}
                }
            }   
            it = fileList.iterator(); 
            while (it.hasNext()) {   
                FileItem item = (FileItem) it.next();   
                // 如果item是文件上传表单域      
                // 获得文件名及路径     
                
                if (item.getName()!= null && item.getName()!="") {
            		File file = new File(FileUtil.getTomcatPicUploadPath());   
                    if (!file.isDirectory()) {   
                        file.mkdirs();   
                    } 
                	String fileName = item.getName().substring(item.getName().lastIndexOf("\\")+1);
                	String name = FileUtil.removeSuffix(item.getName().substring(item.getName().lastIndexOf("\\")+1));
                	String ext = FileUtil.getSuffix(item.getName());
             		String path = FileUtil.getPicUploadPath();
             		String tomcatPath = FileUtil.getTomcatPath();
             		String randomName = FileUtil.getPicRandomName();
             		
            		String bigPath = path+FileUtil.getBigPicName(randomName, ext);
            		String middlePath = path+FileUtil.getMiddlePicName(randomName, ext);
            		String smallPath = path+FileUtil.getSmallPicName(randomName, ext);
            		File tFile = new File(FileUtil.getTomcatPicTempUploadPath()+fileName);
            		File middlePic = null;
            		File smallPic = null;
            		try {
            			BufferedInputStream in = new BufferedInputStream(item.getInputStream());// 获得文件输入流   
                		BufferedOutputStream outStream = new BufferedOutputStream(new FileOutputStream(tFile));// 获得文件输出流   
                		Streams.copy(in, outStream, true);// 开始把文件写到你指定的上传文件夹 
            		} catch (Exception e) {     				
            			e.printStackTrace();
            		}
            		try {
            			smallPic = ImageUtil.getFixedBoundFile(tFile, Integer.parseInt("150"), Integer.parseInt("196"));
            			smallPic.renameTo(new File(tomcatPath+smallPath));
            		} catch (Exception e) {
            			e.printStackTrace();
            		}
            		try {
            			middlePic = tFile;
            			middlePic.renameTo(new File(tomcatPath+middlePath));
            			ImageUtil.markImage(tomcatPath+middlePath);
            		} catch (Exception e) {
            			e.printStackTrace();
            		}
                     //保存到数据库     
                    ProductPath productpath=new ProductPath(Integer.valueOf(id), bigPath, middlePath, smallPath, name, 1);
                    ProductPathService productpathDao = ServiceFactory.getProductPathService();
                    Product product=productDao.findById(Integer.valueOf(id));
                    product.setCoverPath(smallPath);
                    productDao.updatePath(product);
                    productpathDao.add(productpath);
                    FileUtil.deleteFile(tFile);
                    num++;
                }
            }
            if(num>0){
            	productDao.modifyPicNum(Integer.valueOf(id), num);
            }
            
        } catch (FileUploadException ex) {   
            ex.printStackTrace();      
            return;   
        } 
        PrintWriter out = response.getWriter();
        out.print("<script>window.parent.jSuccess('添加成功',null,function(r){window.parent.pictureform.reset();window.parent.location.href='"+request.getContextPath()+"/product?m=searchPic&_url=inner/admin/picture/list.jsp&id="+id+"';});</script>");  
	}
	
	/**
	 * 公开产品图片
	 * @param request
	 * @param response
	 * @throws IOException 
	 */
	public void pubPic(HttpServletRequest request,HttpServletResponse response) throws IOException{
		ProductPathService productpathDao = ServiceFactory.getProductPathService();
		String id=request.getParameter("id");
		String pub=request.getParameter("pub");
		productpathDao.pub(id,Integer.valueOf(pub));
	}
	
	/**
	 * 查看产品图片详情
	 * @param request
	 * @param response
	 * @throws IOException
	 * @throws ServletException 
	 */
	public void findByIdPic(HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException{
		ProductPathService productpathDao = ServiceFactory.getProductPathService();
		String id=request.getParameter("id");
		request.setAttribute("productpath", productpathDao.findById(Integer.valueOf(id)));
		response.setCharacterEncoding("utf-8");
		RequestDispatcher dispatcher=request.getRequestDispatcher(request.getParameter("_url"));
		dispatcher.forward(request, response);
	}
	
	/**
	 * 修改图片产品
	 * @param request
	 * @param response
	 * @throws IOException 
	 */
	public void updatePic(HttpServletRequest request,HttpServletResponse response) throws IOException{
		ProductPathService productpathDao = ServiceFactory.getProductPathService();
		String id=request.getParameter("id");
        String picName=request.getParameter("picName");
        String pub=request.getParameter("pub");
		response.setCharacterEncoding("utf-8");
        ProductPath produ=productpathDao.findById(Integer.valueOf(id));
        produ.setPicName(picName);
        produ.setPub(Integer.valueOf(pub));
        productpathDao.update(produ);
	}
	
	/**
	 * 查看产品详情
	 * @param request
	 * @param response
	 * @throws IOException
	 * @throws ServletException 
	 */
	public void detailPic(HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException{
		ProductPathService productpathDao = ServiceFactory.getProductPathService();
		String id=request.getParameter("id");
		request.setAttribute("productpath", productpathDao.findById(Integer.valueOf(id)));
		response.setCharacterEncoding("utf-8");
		RequestDispatcher dispatcher=request.getRequestDispatcher("inner/admin/picture/detail.jsp");
		dispatcher.forward(request, response);
	}
}
